# coding=utf-8
from django.db import models

# 自定义库
from base_tools.base_model import BaseModel


class PositionFamily(BaseModel):
    key = models.CharField(u"编码", db_column="key", max_length=32)
    val = models.CharField(u"值", db_column="val", max_length=64)

    class Meta:
        db_table = "position_family"
        verbose_name = verbose_name_plural = u"职位集合"

    def __unicode__(self):
        return "%s(%s)" % (self.val, self.key)


class PositionSubFamily(BaseModel):
    key = models.CharField(u"编码", db_column="key", max_length=32)
    val = models.CharField(u"值", db_column="val", max_length=64)
    parent = models.ForeignKey(PositionFamily, verbose_name=u"上级分类", db_column="parent", null=True, blank=True)

    class Meta:
        db_table = "position_sub_family"
        verbose_name = verbose_name_plural = u"职位子集"

    def __unicode__(self):
        return "%s(%s)" % (self.val, self.key)


class PositionMap(BaseModel):
    key = models.CharField(u"编码", db_column="key", max_length=32)
    val = models.CharField(u"值", db_column="val", max_length=64)
    parent = models.ForeignKey(PositionSubFamily, verbose_name=u"上级分类", db_column="parent", null=True, blank=True)

    class Meta:
        db_table = "position_map"
        verbose_name = verbose_name_plural = u"职位字典"

    def __unicode__(self):
        return "%s(%s)" % (self.val, self.key)


class Division(BaseModel):
    key = models.CharField(u"编码", db_column="key", max_length=32)
    val = models.CharField(u"值", db_column="val", max_length=64)
    short = models.CharField(u"缩写值", db_column="short", max_length=16)
    head = models.ForeignKey('StaffInfo', verbose_name=u"负责人", db_column="head", null=True, blank=True,
                             on_delete=models.SET_NULL)

    class Meta:
        db_table = "division"
        verbose_name = verbose_name_plural = u"事业部"

    def __unicode__(self):
        return "%s(%s)" % (self.val, self.key)


class ProductionTeam(BaseModel):
    key = models.CharField(u"编码", db_column="key", max_length=32)
    val = models.CharField(u"值", db_column="val", max_length=64)
    short = models.CharField(u"缩写值", db_column="short", max_length=16)
    parent = models.ForeignKey(Division, verbose_name=u"上级分类", db_column="parent", null=True, blank=True)

    class Meta:
        db_table = "production_team"
        verbose_name = verbose_name_plural = u"生产团队"

    def __unicode__(self):
        return "%s(%s)" % (self.val, self.key)


class StaffInfo(BaseModel):
    cn_name = models.CharField(u"中文名", db_column="cn_name", max_length=64, blank=True)
    en_name = models.CharField(u"英文名", db_column="en_name", max_length=64, blank=True)
    employee_id = models.CharField(u"工号", db_column="emp_id", max_length=64, blank=True)
    qr_code = models.CharField(u"二维码地址", db_column="qr_code", max_length=256, blank=True)
    # 员工分类:本地(Local FTE)/实习生(Intern)/外派(Dispatch)/顾问(Consultant)/外籍员工(Expats)/兼职(Part-time Worker)
    job_nature = models.CharField(u"员工分类", db_column="job_nature", max_length=32, blank=True)
    job_level = models.CharField(u"职位级别", db_column="job_level", max_length=32, blank=True)
    # 工作类别:生产线(Production)/公司管理(Company Management)/发布(Publish)/市场(Business)
    emp_type = models.CharField(u"工作类别", db_column="emp_type", max_length=32, blank=True)
    work_email = models.CharField(u"邮箱", db_column="wemail", max_length=256, blank=True)
    is_on_board = models.BooleanField(u"是在在职", db_column="ioboard", default=True)
    on_board_date = models.CharField(u"入职日期", db_column="obdate", max_length=16, blank=True)
    departure_date = models.CharField(u"离职日期", db_column="dtdate", max_length=16, blank=True)
    position = models.ForeignKey(PositionMap, verbose_name=u"当前职位", db_column="postion", related_name="staff",
                                 null=True, blank=True, on_delete=models.SET_NULL)
    production_team = models.ManyToManyField(ProductionTeam, verbose_name=u"当前生产团队", null=True, blank=True)
    # 由于考勤，请假而加入的字段
    attend_no=models.CharField(u'考勤号', db_column='attend_no', max_length=64, blank=True)
    workshift=models.CharField(u'作息时间', db_column='workshift', max_length=64, blank=True)
    startjob_date=models.CharField(u'开始工作日期', max_length=100, blank=True)
    func_leader=models.ForeignKey('StaffInfo', verbose_name=u'职能主管', db_column='func_leader', null=True, blank=True, related_name='staff_employee')
    pro_leader=models.ForeignKey('StaffInfo', verbose_name=u'项目主管', db_column='pro_leader', null=True, blank=True)      
     
    class Meta:
        db_table = "staff_info"
        verbose_name = verbose_name_plural = u"职员信息"

    def __unicode__(self):
        return "%s(%s)" % (self.cn_name, self.employee_id)


class PersonInfo(BaseModel):
    # 个人信息
    staff_info = models.ForeignKey(StaffInfo, verbose_name=u"职员信息", db_column='staffinfo_id')
    gender = models.CharField(u"性别", db_column="gender", max_length=16)
    age = models.CharField(u"年龄", db_column="age", max_length=8)
    born_date = models.CharField(u"出生日期", db_column="born_date", max_length=16)
    nation = models.CharField(u"民族", db_column="nation", max_length=128)
    nationality = models.CharField(u"国籍", db_column="nationality", max_length=128)
    native_place = models.CharField(u"籍贯", db_column="native_place", max_length=128)
    health = models.CharField(u"健康状况", db_column="health", max_length=128)
    party = models.CharField(u"政治面貌", db_column="party", max_length=128)
    former_name = models.CharField(u"曾用名", db_column="former_name", max_length=128)
    formal_photo = models.CharField(u"证件照", db_column="formal_photo", max_length=256)
    life_photo = models.CharField(u"生活照", db_column="life_photo", max_length=256)
    social_ins_place = models.CharField(u"社保关系所在地", db_column="siplace", max_length=128)
    house_fund_place = models.CharField(u"公积金缴存地", db_column="hfplace", max_length=128)

    # 证件信息
    cert_type = models.CharField(u"证件类型", db_column="cert_type", max_length=128)
    cert_number = models.CharField(u"证件号码", db_column="cert_number", max_length=32)
    cert_address = models.CharField(u"证件地址", db_column="cert_address", max_length=128)
    cert_valid_date = models.CharField(u"证件有效日期", db_column="cert_valid_date", max_length=16)
    domicile_place = models.CharField(u"户口所在地", db_column="domicile_place", max_length=128)
    domicile_type = models.CharField(u"户籍类型", db_column="domicile_type", max_length=32)

    # 联系方式
    tel = models.CharField(u"手机号码", db_column="tel", max_length=64)
    home_tel = models.CharField(u"家庭号码", db_column="htel", max_length=64)
    email = models.CharField(u"私人邮箱", db_column="email", max_length=128)
    qq = models.CharField(u"QQ号", db_column="qq", max_length=32)
    weixin = models.CharField(u"微信号", db_column="weixin", max_length=32)
    live_address = models.CharField(u"现家庭住址", db_column="live_address", max_length=256)
    emergency_contact = models.CharField(u"紧急联络人", db_column="emergency_contact", max_length=256)

    # 家庭信息
    marriage = models.CharField(u"婚姻状况", db_column="marriage", max_length=16)
    fertility = models.CharField(u"生育状况", db_column="fertility", max_length=16)
    child = models.CharField(u"小孩情况", db_column="child", max_length=256)
    family = models.TextField(u"主要家庭成员", db_column="family")

    # 个性信息
    hobby = models.CharField(u"兴趣爱好", db_column="hobby", max_length=256)
    height = models.CharField(u"身高", db_column="height", max_length=16)
    weight = models.CharField(u"体重", db_column="weight", max_length=16)
    blood = models.CharField(u"血型", db_column="blood", max_length=16)
    illness = models.TextField(u"重大疾病手术史", db_column="illness")
    criminal = models.TextField(u"犯罪史", db_column="criminal")

    class Meta:
        db_table = "person_info"
        verbose_name = verbose_name_plural = u"个人基本信息"

    def __unicode__(self):
        return "%s(%s)" % (self.gender, self.age)


class EducationExp(BaseModel):
    staff = models.ForeignKey(StaffInfo, verbose_name=u"职员信息", db_column='staffinfo_id')
    school = models.CharField(u"学校", db_column="school", max_length=256, blank=True)
    major = models.CharField(u"专业", db_column="major", max_length=256, blank=True)
    degree = models.CharField(u"学位", db_column="degree", max_length=128, blank=True)
    start_date = models.CharField(u"开始日期", db_column="sdate", max_length=16, blank=True)
    end_date = models.CharField(u"结束日期", db_column="edate", max_length=16, blank=True)

    class Meta:
        db_table = "education_exp"
        verbose_name = verbose_name_plural = u"教育经历"


class WorkExp(BaseModel):
    staff = models.ForeignKey(StaffInfo, verbose_name=u"职员信息", db_column='staffinfo_id')
    company = models.CharField(u"公司名", db_column="company", max_length=128, blank=True)
    city = models.CharField(u"所在城市", db_column="city", max_length=64, blank=True)
    start_end_date = models.CharField(u"起止日期", db_column="sedate", max_length=128, blank=True)
    department = models.CharField(u"职位(部门)", db_column="department", max_length=128, blank=True)
    salary = models.CharField(u"薪资构成", db_column="salary", max_length=128, blank=True)
    is_departure = models.BooleanField(u"是否和原公司解除劳动关系", db_column="is_departure", default=True)
    is_lawsuit = models.BooleanField(u"是否和原公司有未了诉讼", db_column="is_lawsuit", default=True)

    class Meta:
        db_table = "work_exp"
        verbose_name = verbose_name_plural = u"工作经历"


class MokiExp(BaseModel):
    staff = models.ForeignKey(StaffInfo, verbose_name=u"职员信息", db_column='staffinfo_id')
    start_date = models.CharField(u"开始日期", db_column="sdate", max_length=16, blank=True)
    end_date = models.CharField(u"结束日期", db_column="edate", max_length=16, blank=True)
    job_nature = models.CharField(u"员工分类", db_column="job_nature", max_length=32, blank=True)
    job_level = models.CharField(u"职位级别", db_column="job_level", max_length=32, blank=True)
    emp_type = models.CharField(u"工作类别", db_column="emp_type", max_length=32, blank=True)
    details_info = models.TextField(u"详细信息", db_column="details", blank=True)
    reason = models.CharField(u"职位变更原因", db_column="reason", max_length=256, blank=True)

    class Meta:
        db_table = "moki_exp"
        verbose_name = verbose_name_plural = u"摩奇经历"
